﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ToWaTimeReportMVC4.Models;

namespace ToWaTimeReportMVC4.Controllers
{
    [Authorize]
    public class AdminController : Controller
    {

        ToWaService service = new ToWaService();

        //
        // GET: /Admin/

        public ActionResult Index()
        {
            return View();
        }

        //
        // GET: /Admin/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Admin/Create

        public ActionResult CreateUser()
        {
            return View();
        } 

        //
        // POST: /Admin/Create

        [HttpPost]
        public ActionResult CreateUser(UserWrapper userWrapper)
        {
            //try
            //{
                // TODO: Add insert logic here
                service.AddUser(userWrapper.Username, userWrapper.Password, userWrapper.Password, userWrapper.Email, service.ConvertTypeToInt(userWrapper.Type), userWrapper.Salary, 0);

                return RedirectToAction("Index", "Home");
            //}
            //catch
            //{
            //    return View();
            //}
        }
        
        //
        // GET: /Admin/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Admin/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Admin/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Admin/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
